//TODO 实现 bind() ★★
//TODO 实现 apply() ★★
//TODO 实现 call() ★★
//TODO 实现 instanceof ★
//TODO 实现 new ★
//TODO 实现 jsonp ★★★
//TODO 实现 Promise ★★★
//TODO 实现 Promise.all() ★★★
//TODO 实现 Promise.race() ★
//TODO 实现 EventEmitter 订阅监听模式 ★★
//TODO setTimout 实现 setInterval ★
//TODO 深拷贝 ★★★
class Node {
    constructor(element) {
        this.element = element;
        this.next = null;
    }
}

class LinkedList {
    constructor() {
        this.head = null;
        this.count = 0;
    }
    insert(element) {
        this.count++
            let node = new Node(element)
        if (this.head == null) {
            this.head = node;
        } else {
            let current = this.head;
            while (current.next) {
                current = current.next;
            }
            current.next = node;
        }
    }
    display() {
        let currNode = this.head;
        while (!(currNode.next == null)) {
            console.log(currNode.next.element);
            currNode = currNode.next
        }
    }
}
let l1 = new LinkedList();
l1.insert(1);
l1.insert(2);
l1.insert(3);
l1.insert(4);
console.log(l1);
l1.display()
    /* (() => {
let prev = null;
let head = l1.head;
while (head != null) {
    let temp = head.next;
    head.next = prev;
    prev = head;
    head = temp
}
console.log(prev);
})() */